package com.hna.eking.AirlineServer.Exception;

import java.util.HashMap;
import java.util.Map;
/**
*
*  执行时 全局自定义异常
* Date : 2018-9-11
* Description: 执行时 全局异常
* 			
* Copyright: Copyright &copy; 2018
* Company :aivac
* 
* @author APP BD lele
* @version  V1.0
* ------------------------------------------------------------
*  修改历史
*  序号 日期 修改人 修改原因
*  1 
*/
public class RunServiceException extends RuntimeException{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	/*
	 * 设置错误信息
	 * msg 出错信息
	 * */
	public RunServiceException(String msg) {
		super(msg);
		code = SERVER_INTERNAL_ERR;
	}
	/*
	 * 设置错误信息
	 * msg 出错信息
	 * code 错误码
	 * */
	public RunServiceException(int code, String msg) {
		super(map.get(code) + "-" + msg);
		this.code = code;
	}
	/*
	 * 设置错误码
	 * code 错误码
	 * */
	public void setCode(int code) {
		this.code = code;
	}
	
	/*
	 * 设置错误码，并获取出错信息
	 * code 错误码
	 * */
	public RunServiceException(int code) {		
		this.code = code;
	}
	
	public int getCode() {
		return code;
	}
	private int code;//错误码
	
	public final static Map map = new HashMap();
	static {
		map.put(100, "DATA_NOT_FOUND");
		map.put(200, "SUCCESS");
		map.put(1001, "UNKNOW_FAILED");
		map.put(404, "RESOURCE_NOT_FOUND");
		map.put(400, "BAD_REQUEST");
		map.put(401, "UNAUTHORIZED");
		map.put(403, "FORBIDDEN");
		map.put(500, "SERVER_INTERNAL_ERR");
		map.put(1002, "user not be null");
		map.put(1003, "database unkonw error");
		map.put(1004, "json format error");
		map.put(1005, "update not found row");
		map.put(1006, "unique key error");
		map.put(1007, "File upload Failed");
		map.put(1008, "File is null");
		map.put(1009, "compress error");
		map.put(1010, "interface not surport map type area");
	};
	private String Local = "ZH";
	
	public final static Integer DATA_NOT_FOUND = 100;//数据未找到错误
	public final static Integer SUCCESS = 200;//成功
	public final static Integer UNKNOW_FAILED = 1001;//未知错误
	public final static Integer REQ_NOT_FOUND = 404;//资源未找到
	public final static Integer BAD_REQUEST = 400;//访问参数有问题
	public final static Integer FORBIDDEN = 403;//禁止访问此资源
	public final static Integer UNAUTHORIZED = 401;//未授权
	public final static Integer SERVER_INTERNAL_ERR = 500;//服务内部错误
	public final static Integer UNKONW_USER = 1002;//用户为空
	public final static Integer DATABASE_ERROR = 1003;//数据库未知错误
	public final static Integer JSON_FORMAT_ERROR = 1004;//json 格式错误
	public final static Integer UPDATE_NOT_FOUND = 1005;//无更新数据
	public final static Integer  UNIQUE_ERROR = 1006;//违法唯一
	public final static Integer  FILE_UPLOAD_FAIL = 1007;//文件上传失败
	public final static Integer  FILE_UPLOAD_NULL= 1008;//文件上传为空
	public final static Integer  ZIP_FILE_FAILED= 1009;//文件压缩失败
	public final static Integer  UNSPT_MAP_TYPE= 1010;//不支持修改区域图
	public static String getMessage(Integer Code) {
		
		return (String) map.get(Code);
	}
	public String getMessage() {
		
		return (String) map.get(code);
	}
}
